

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>小说列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
    <style>
      .layui-card span[lay-separator] {
        margin: 0 10px;
        color: #999;
        font-weight: bold;
      }
    </style>
  </head>

<body>

  <div class="layui-fluid" id="LAY-component-grid-stack">
    <div class="layui-card">

        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <blockquote class="layui-elem-quote layui-text">
                添加专属的书籍，除已授权代理外，其他代理及下属投放号后台将不会展示此书！！（已设置App开屏、已设置读者弹窗、已提取链接不做判断！）
            </blockquote>
          <div class="layui-form-item">
        <div class="layui-inline">
          <input type="text" name="id" placeholder="小说ID" autocomplete="off" class="layui-input" value="{$Request.param.id}">
        </div>

        <div class="layui-inline">
          <input type="text" name="title" placeholder="小说名" autocomplete="off" class="layui-input" value="{$Request.param.title}">
        </div>

            <div class="layui-inline">
              <select name="scale">
                <option value="">选择评级</option>
                <option value="S" {if $Request.param.scale eq 'S'}selected{/if}>S级别</option>
                <option value="A" {if $Request.param.scale eq 'A'}selected{/if}>A级别</option>
                <option value="B" {if $Request.param.scale eq 'B'}selected{/if}>B级别</option>
                <option value="C" {if $Request.param.scale eq 'C'}selected{/if}>C级别</option>
              </select>
            </div>

        <div class="layui-inline">
          <select name="freq_id">
            <option value="">选择频道</option>
            {foreach $freqArr as $v}
            <option value="{$v.id}" {if $Request.param.freq_id eq $v.id}selected{/if}>{$v.name}</option>
            {/foreach}
          </select>
        </div>

        <div class="layui-inline">
          <select name="class_id"  lay-search>
            <option value="">选择分类</option>
            {foreach $classArr as $v}
            <option value="{$v.id}" {if $Request.param.class_id eq $v.id}selected{/if}>{$v.name}</option>
            {/foreach}
          </select>
        </div>


            <div class="layui-inline">
              <select name="update_status">
                <option value="">连载状态</option>
                <option value="0" {if $Request.param.update_status eq 0 && $Request.param.update_status != null}selected{/if}>连载</option>
                <option value="1" {if $Request.param.update_status eq 1}selected{/if}>完结</option>
                <option value="2" {if $Request.param.update_status eq 2}selected{/if}>弃更</option>
              </select>
            </div>


              <div class="layui-inline">
                  <select name="agent_id"  lay-search>
                      <option value="">选择已授权代理</option>
                      {foreach $agents as $v}
                      <option value="{$v.id}" {if $Request.param.agent_id eq $v.id}selected{/if}>{$v.account}</option>
                      {/foreach}
                  </select>
              </div>

          <div class="layui-inline">
            <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-search">
              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>
          </div>

          </div>
        </div>


       <div class="layui-card-body">
        <script type="text/html" id="toolbarDemo">
          <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
          </div>
        </script>

        <script type="text/html" id="classTpl">
          {{#  if(d.freq && d.novel_class){ }}
          {{d.freq.name}}<span lay-separator="">·</span>{{d.novel_class.name}}
          {{#  } }}
        </script>

        <table id="LAY-user-back-role" lay-filter="LAY-user-back-role"></table>
        <script type="text/html" id="table-useradmin-admin">
          <a class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-auz"></i>授权</a>
          <a class="layui-btn layui-btn-primary layui-border-red layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete" ></i>移除</a>
        </script>
      </div>
    </div>

  </div>



  <script src="/static/layuiadmin/layui/layui.js"></script>
  <script>
    layui.config({
      base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
      index: 'lib/index' //主入口模块
    }).use(['index','table'], function () {
      var $ = layui.$
              ,admin = layui.admin
              ,table = layui.table
              ,form = layui.form;

      //监听搜索
      form.on('submit(LAY-user-back-search)', function(data){
        var field = data.field;

        //执行重载
        table.reload('LAY-user-back-role', {
            where: field
            ,page: {
                curr: 1  // 将页码重置为第一页
            }
        });
      });

      table.render({
        elem: '#LAY-user-back-role'
        , url: '/novel/exclusiveNovelList'
        , response: {
          statusCode: 1 //规定成功的状态码，本来是：0，现在统一改为1
        }
        , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
        , defaultToolbar: false
        , page: true //开启分页
        , limit: 20
        , cols: [[
          {field: 'id', width: 80, title: 'ID'}
          , {field: 'title', title: '小说名', minWidth: 180,width: 220}
          , {
            field: 'scale', title: '评级', templet: function (d) {
              if (d.scale === 'S') {
                return '<span style="color: #FF5722;">S级</span>'
              } else if (d.scale === 'A') {
                return '<span style="color: #FFB800;">A级</span>'
              } else if (d.scale === 'B') {
                return '<span style="color: #01AAED;">B级</span>'
              } else if (d.scale === 'C') {
                return '<span style="color: #5FB878;">C级</span>'
              } else {
                return '';
              }
            }, align: 'center'
          }
          , {field: 'class', title: '频道<span lay-separator="">·</span>分类', templet: '#classTpl', align: 'center',minWidth:180}
          , {field: 'in_shelf', title: '是否上架', templet: function (d) {
              if (d.in_shelf === 0) {
                return '<span style="color: #FF5722;">绝对下架</span>';
              } else if (d.in_shelf === 2) {
                  return '<span style="color: #FF5722;">下架</span>';
              }else {
                return '上架';
              }
            }, align: 'center'}
          , {field: 'agents_count', title: '专属代理数量', align: 'center'}
          , {title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#table-useradmin-admin'}
        ]]
      });

      //头工具栏事件
      table.on('toolbar(LAY-user-back-role)', function (obj) {
        var checkStatus = table.checkStatus(obj.config.id);
        switch (obj.event) {
          case 'add':
            layer.open({
              type: 2
              ,title: '添加专属书籍'
              ,content: '/novel/addExclusiveForm.html'
              ,offset: '5px'
              ,area: ['720px', '650px']
              ,btn: ['确定', '取消']
              ,yes: function(index, layero){
                var iframeWindow = window['layui-layer-iframe'+ index]
                        ,submit = layero.find('iframe').contents().find("#LAY-user-role-submit");

                //监听提交
                iframeWindow.layui.form.on('submit(LAY-user-role-submit)', function(data){
                  var field = data.field; //获取提交的字段
                  //提交 Ajax 成功后，静态更新表格中的数据
                  //$.ajax({});
                  admin.req({
                    url: '/novel/setExclusive'
                    , type: "POST"
                    , data: field
                    , done: function (res) {
                      layer.msg('添加成功', {icon: 1, time: 2000}, function () {
                          table.reload('LAY-user-back-role');
                          layer.closeAll(); //关闭弹层
                      });
                    },not_finish:function (res) {
                      layer.msg(res.msg);
                    }
                  });
                });
                submit.trigger('click');
              }
            });
            break;
        }
      });


        //监听工具条
      table.on('tool(LAY-user-back-role)', function(obj){
            var data = obj.data;
            if(obj.event === 'edit'){
                var tr = $(obj.tr);
                layer.open({
                    type: 2
                    ,title: '修改授权'
                    ,offset: '15px'
                    ,content: '/novel/editExclusiveForm.html?nid=' + obj.data.id
                    ,area: ['720px', '650px']
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        var iframeWindow = window['layui-layer-iframe'+ index]
                            ,submit = layero.find('iframe').contents().find("#LAY-user-role-submit");

                        //监听提交
                        iframeWindow.layui.form.on('submit(LAY-user-role-submit)', function(data){
                            var field = data.field; //获取提交的字段

                            //提交 Ajax 成功后，静态更新表格中的数据
                            //$.ajax({});
                            admin.req({
                                url: '/novel/setExclusive'
                                , type: "POST"
                                , data: field
                                , done: function (res) {
                                    layer.msg('修改授权成功', {icon: 1, time: 1000}, function () {
                                        table.reload('LAY-user-back-role');
                                        layer.close(index); //关闭弹层
                                    });
                                },not_finish:function (res) {
                                    layer.msg(res.msg);
                                }
                            });
                        });

                        submit.trigger('click');
                    }
                    ,success: function(layero, index){

                    }
                })
            }else if (obj.event === 'del'){
                layer.confirm('确认移除《'+obj.data.title+'》？', {icon: 3, title:false}, function(index){
                    admin.req({
                        url: '/novel/delExclusive'
                        , type: "POST"
                        , data: {'nid': obj.data.id}
                        , done: function (res) {
                            layer.msg('移除成功', {icon: 1, time: 1000}, function () {
                                obj.del();
                                layer.close(index);
                            });
                        },not_finish:function (res) {
                            layer.msg(res.msg);
                        }
                    });
                });
            }
        });

    });
  </script>
</body>